﻿@page "/inputs"

<Block Title="Input 文本输入框" Introduction="提供基本的文本录入组件" CodeFile="input.1.txt">
    <div class="form-inline">
        <div class="row">
            <div class="form-group col-12">
                <label class="control-label">基本用法</label>
                <BootstrapInput TItem="string" placeholder="请输入 ..."></BootstrapInput>
            </div>
        </div>
    </div>
</Block>

<Block Title="单向绑定数据" Introduction="显示组件内变量值" CodeFile="input.2.txt">
    <div class="form-inline">
        <div class="row">
            <div class="form-group col-12">
                <label class="control-label">单向绑定</label>
                <BootstrapInput TItem="string" placeholder="请输入 ..." Value="@InputValue"></BootstrapInput>
            </div>
        </div>
    </div>
</Block>

<Block Title="双向绑定数据" Introduction="绑定组件内变量，数据自动同步" CodeFile="input.3.txt">
    <div class="form-inline">
        <div class="row">
            <div class="form-group col-12">
                <label class="control-label">单向绑定</label>
                <BootstrapInput TItem="string" placeholder="请输入 ..." @bind-Value="@BindValue">
                </BootstrapInput>
            </div>
            <div class="form-group col-12">
                <div>绑定数值: @BindValue</div>
            </div>
        </div>
    </div>
</Block>

<Block Title="客户端验证" Introduction="根据自定义验证规则进行数据有效性检查并自动提示" CodeFile="input.4.txt">
    <ValidateForm class="form-inline" Model="@Model">
        <div class="row">
            <div class="form-group col-12">
                <label class="control-label">数据验证</label>
                <BootstrapInput TItem="string" maxlength="5" placeholder="请输入 ..." @bind-Value="@Model.Name">
                    <RequiredValidator />
                    <StringLengthValidator Length="5" />
                </BootstrapInput>
            </div>
        </div>
    </ValidateForm>
</Block>

<AttributeTable Items="@GetAttributes()" />

@code {
    private string InputValue => "数据值";

    private string BindValue { get; set; } = "绑定值";

    private FooModel Model { get; set; } = new FooModel();

    private class FooModel
    {
        public string Name { get; set; } = "张三";
    }

    private IEnumerable<AttributeItem> GetAttributes()
    {
        return new AttributeItem[]
        {
            new AttributeItem() {
                Name = "ChildContent",
                Description = "验证控件",
                Type = "RenderFragment",
                ValueList = " — ",
                DefaultValue = " — "
            },
            new AttributeItem()
            {
                Name = "type",
                Description = "控件类型",
                Type = "string",
                ValueList = "text / number / email / url",
                DefaultValue = "text"
            },
        };
    }
}
